package com.imooc.coupon.converter;


import com.alibaba.fastjson.JSON;
import com.imooc.coupon.vo.TemplateRule;

import javax.persistence.AttributeConverter;

/**
 * 规则枚举类转换器
 * @Author Administrator
 * @Date 2021/6/7 22:13
 * @Version 1.0
 */
public class RuleConverter implements AttributeConverter<TemplateRule, String> {

    @Override
    public String convertToDatabaseColumn(TemplateRule teplateRule) {
        return JSON.toJSONString(teplateRule)  ;
    }

    @Override
    public TemplateRule convertToEntityAttribute(String teplateRule) {
        return JSON.parseObject(teplateRule, TemplateRule.class);
    }
}
